home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility3 / blandmdi.zip / BLANDINI.C next >
C/C++ Source or Header  |  1991-05-03  |  5KB  |  175 lines

  1. /*
  2.  *
  3.  *  MODULE   : BlandIni.c
  4.  *
  5.  *  PURPOSE  : Contains initialization code for BlandMDI.
  6.  *
  7.  *  FUNCTIONS:
  8.  *
  9.  *      InitializeApplication() - Sets up Class data structure
  10.  *                                and registers window class.
  11.  *
  12.  *      InitializeInstance ()   - Does a per-instance initialization
  13.  *                                of BlandMDI. Creates the "frame"
  14.  *                                and MDI client.
  15.  *
  16.  *      MakeNewChild ()         - Creates a new MDI child window
  17.  *
  18.  * Copyright 1991 Microsoft Corporation. All rights reserved.
  19.  */
  20.  
  21. /*------------------------  #includes  --------------------------------*/
  22.  
  23. #include "BlandMDI.h"
  24.  
  25.  
  26. /*------------------------  global variables  -------------------------*/
  27.  
  28. char szFrame[] = "bland frame";   // Class name for "frame" window
  29. char szChild[] = "bland child";   // Class name for MDI window
  30.  
  31.  
  32. /*--------------------- InitializeApplication  -------------------------*/
  33. /*
  34.  *
  35.  *  FUNCTION   : InitializeApplication ()
  36.  *
  37.  *  PURPOSE    : Sets up the class data structures and does a one-time
  38.  *               initialization of the app by registering the window classes
  39.  *
  40.  *  RETURNS    : TRUE  - If RegisterClass() was successful for both classes.
  41.  *               FALSE - otherwise.
  42.  *
  43.  */
  44.  
  45. BOOL FAR PASCAL InitializeApplication()
  46. {
  47.     WNDCLASS  wc;
  48.  
  49.     // Register the frame class 
  50.     wc.style         = 0;
  51.     wc.lpfnWndProc   = BlandFrameWndProc;
  52.     wc.cbClsExtra    = 0;
  53.     wc.cbWndExtra    = 0;
  54.     wc.hInstance     = hInst;
  55.     wc.hIcon         = LoadIcon(hInst, IDBLANDFRAME);
  56.     wc.hCursor       = LoadCursor(NULL,IDC_ARROW);
  57.     wc.hbrBackground = COLOR_APPWORKSPACE+1;
  58.     wc.lpszMenuName  = IDBLANDMENU;
  59.     wc.lpszClassName = szFrame;
  60.  
  61.     if (RegisterClass (&wc))
  62.       {
  63.       // Register the MDI child class 
  64.       wc.lpfnWndProc   = BlandMDIChildWndProc;
  65.       wc.hIcon         = LoadIcon(hInst,IDBLANDCHILD);
  66.       wc.lpszMenuName  = NULL;
  67.       wc.cbWndExtra    = CBWNDEXTRA;
  68.       wc.lpszClassName = szChild;
  69.  
  70.       if (RegisterClass(&wc))
  71.         return TRUE;
  72.       }
  73.  
  74.     return FALSE;
  75. }
  76.  
  77.  
  78. /*----------------------  InitializeInstance  --------------------------*/
  79. /*
  80.  *
  81.  *  FUNCTION   : InitializeInstance ()
  82.  *
  83.  *  PURPOSE    : Performs a per-instance initialization of BlandMDI. It
  84.  *               also creates the frame and one MDI child window.
  85.  *
  86.  *  RETURNS    : TRUE  - If initialization was successful.
  87.  *               FALSE - otherwise.
  88.  *
  89.  */
  90.  
  91.  
  92. BOOL FAR PASCAL InitializeInstance(LPSTR lpCmdLine, WORD nCmdShow)
  93. {
  94.     extern HWND   hwndMDIClient;
  95.            char   sz[80], *pCmdLine;
  96.            HDC    hdc;
  97.            HMENU  hmenu;
  98.  
  99.     // Get the base window title
  100.     LoadString (hInst, IDS_APPNAME, sz, sizeof(sz));
  101.  
  102.     // Create the frame 
  103.     // MDI Client window is created in frame's WM_CREATE case
  104.     hwndFrame = CreateWindow (szFrame,
  105.             sz,
  106.             WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  107.             CW_USEDEFAULT,
  108.             0,
  109.             CW_USEDEFAULT,
  110.             0,
  111.             NULL,
  112.             NULL,
  113.             hInst,
  114.             NULL);
  115.  
  116.     if (hwndFrame && hwndMDIClient)
  117.         {
  118.         // Display the frame window 
  119.         ShowWindow (hwndFrame, nCmdShow);
  120.         UpdateWindow (hwndFrame);
  121.  
  122.         // Make the first MDI child window 
  123.         MakeNewChild ("Initial Window");
  124.         return TRUE;
  125.         }
  126.  
  127.     return FALSE;
  128. }
  129.  
  130.  
  131. /*----------------   MakeNewChild  -----------------------------*/
  132. /*
  133.  *
  134.  *  FUNCTION   : MakeNewChild (lpName)
  135.  *
  136.  *  PURPOSE    : Creates a new MDI child window.
  137.  *
  138.  *  RETURNS    : HWND  - A handle to the new window.
  139.  *
  140.  */
  141.  
  142. HWND FAR PASCAL MakeNewChild(char *pName)
  143. {
  144.     HWND            hwnd;
  145.     char            sz[160];
  146.     MDICREATESTRUCT mcs;
  147.  
  148.     if (!pName)
  149.         {
  150.         // pName parameter is NULL -- load the "Untitled" string 
  151.         // from STRINGTABLE
  152.         LoadString (hInst, IDS_UNTITLED, sz, sizeof(sz));
  153.         mcs.szTitle = (LPSTR)sz;
  154.         }
  155.     else
  156.         {
  157.         mcs.szTitle = (LPSTR)pName; /* Fully qualified pathname*/
  158.         }
  159.  
  160.     mcs.szClass    = szChild;
  161.     mcs.hOwner     = hInst;
  162.     mcs.x = mcs.cx = CW_USEDEFAULT;  // Use the default size for the window
  163.     mcs.y = mcs.cy = CW_USEDEFAULT;
  164.     mcs.style      = styleDefault;   // Set the style DWORD of the window
  165.                                      // to default
  166.     // tell the MDI Client to create the child 
  167.     hwnd = (WORD)SendMessage (hwndMDIClient,
  168.                               WM_MDICREATE,
  169.                               0,
  170.                               (LONG)(LPMDICREATESTRUCT)&mcs);
  171.     ShowWindow(hwnd, SW_SHOW);
  172.  
  173.     return hwnd;
  174. }
  175.